﻿using UnityEngine;
using System.Collections;

/// <summary>
/// 游戏的输入控制管理， 在这里将逐步封装所有的 类型游戏 输入
/// FPS 、 手游触屏 、 PC键盘 、VR 设备输入等等 。。。
/// </summary>
public class InputBox : NorSingleton<Input>
{
    /// <summary>
    /// Unity的 按键状态
    /// </summary>
    public class KeyState
    {
        public string AxisName;
        public float PressTime = 10.0f;
        public float ReleaseTime = 10.0f;
        /// <summary> 0=release 1=click 2=double click /// </summary>
        public float Pressed = 0;
        /// <summary> 用于和 动作的 映射绑定</summary>
        public float Operation = 0;
    }

    public KeyState[] KeyStates = new KeyState[(int)KeyList.KL_Max];
    const float DoubleClickTime = 0.4f;
    const float LongPressedTime = 0.3f;
    /// <summary>输入方向</summary>
    Vector2 mInputVector = Vector2.zero;
    /// <summary>上次输入方向向量 </summary>
    Vector2 mLastInputVector = Vector2.one;

    bool mMoveKeyDown = false;
    //
    bool mEnable = true;

    public Vector2 InputDirection { get { return mInputVector; } }

    protected override void OnInit()
    {
        for (int i = 0; i < KeyStates.Length; i++)
        {
            KeyStates[i] = new KeyState();
        }
        //KeyStates[(int)EKeyList.KL_Jump].AxisName = "Jump";
        //KeyStates[(int)EKeyList.KL_Attack].AxisName = "Attack";
        //KeyStates[(int)EKeyList.KL_SubAttack].AxisName = "SubAttack";
        //KeyStates[(int)EKeyList.KL_SkillAttack].AxisName = "SkillAttack";
        //KeyStates[(int)EKeyList.KL_AuxKey].AxisName = "AuxKey";
    }
    public void Update(float deltaTime)
    {
        if (false==mEnable)
        {
            return;
        }


        // 先更新 按键状态
        UpdateKeyStatus(deltaTime);

    }
    void UpdateKeyStatus(float deltaTime)
    {
        // check the key status.
        for (int idx = 0; idx < KeyStates.Length; idx++)
        {
            KeyState keyStatus = KeyStates[idx];
            keyStatus.PressTime += deltaTime;
            keyStatus.ReleaseTime += deltaTime;

            if (string.IsNullOrEmpty(keyStatus.AxisName))
                continue;

            //////bool pressed = Input.GetAxis(keyStatus.AxisName) > 0;
            //////if (pressed && keyStatus.Pressed == 0)
            //////    OnKeyDown(keyStatus);

            //////if (!pressed && keyStatus.Pressed != 0)
            //////    OnKeyUp(keyStatus);
        }
    }

}
